package org.leumasjaffe.math.probability;

import java.util.Random;

import org.eclipse.jdt.annotation.NonNullByDefault;

@NonNullByDefault
public abstract class AbstractRV {
	final Random rand;
	
	AbstractRV() {
		this.rand = new Random();
	}
	
	AbstractRV(Random r) {
		this.rand = r;
	}
	
	protected double getRand() {
		return this.rand.nextDouble();
	}	
	
	public double getX() {
		double u = this.rand.nextDouble();
		return calcX(u);
	}
	
	/** Returns the Expected value of this Random Distribution */
	public abstract double getEV();
	
	/** Returns the Variance of this Random Distribution */
	public abstract double getVar();
	
	
	public double getStd() {
		return Math.sqrt(getVar());
	}
	
	/** Returns the probability of the given result in this Random Distribution */
	public abstract double getP(double x);
	
	/** Calculates the result of this Random Distribution from a given probability (reverse CDF) */
	public abstract double calcX(double p);
	
	/** Returns the Cumulative probability of the given result from this Random Distribution */
	public abstract double getF(double x);
	
	static protected boolean isProb(double p) {
		return p >= 0 && p <= 1;
	}

}
